﻿using BLL.Base;
using BLL.custom;
using CommandService;
using Entity;
using Entity.DbEntity;
using Entity.FrameEntity;
using Entity.ViewEntity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using U8Service;

namespace BLL
{
    public class U8Order : PubMethod
    {
        HttpAgreement http;
        Commands cmd;
        LoginInfo userLogin;
        Tools.TxtLogHelper txt;
        ReturnResult rsl;
        CuDbHelper cuHelper;
        List<InOutResult> resultList;
        public U8Order()
        {
            http = new HttpAgreement();
            cmd = new Commands();
            userLogin = new LoginInfo();
            txt = new Tools.TxtLogHelper();
            cuHelper = new CuDbHelper();
            resultList = new List<InOutResult>();
        }
        /// <summary>
        /// 产成品入库
        /// </summary>
        /// <param name="tempDatas">扫描数据</param>
        /// <param name="usCode">提交人员信息</param>
        /// <returns></returns>
        public ReturnResult productInWareHouse(List<DbTempScanData> tempDatas, string baseCode, string userCode)
        {
            rsl = new ReturnResult();
            StringBuilder sb = new StringBuilder();
            List<InOutResult> resultList = new List<InOutResult>();
            List<string> bars = new List<string>();
            try
            {
                var pars = new Dictionary<string, object>();
                string msg = "";
                var datas = this.ProductInData(tempDatas[0].tempCode, ref msg, ref bars);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(userCode, baseCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                pars["System"] = sysPar;

                #region 表头参数
                var head = new Dictionary<string, object>();
                head["ddate"] = tempDatas[0].happenDate; //发生日期
                head["cwhcode"] = tempDatas[0].wareHouse; //仓库
                head["csource"] = "生产入库";//单据来源
                pars["Head"] = head;
                #endregion

                #region 表体数据
                pars["List"] = datas;
                #endregion
                pars["isBlue"] = "1";

                string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "ProductIn");
                var postData = JsonConvert.SerializeObject(pars);

                msg = http.PostJson(url, postData);
                txt.AddLogMsg(string.Format("产成品入库,参数：{0},结果：{1}", postData, msg));

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    var apiResult = JsonConvert.DeserializeObject<ReturnResult>(msg);
                    InOutResult or = new InOutResult();
                    if (apiResult.Result)
                    {
                        or.SuccOrderCode = apiResult.Data.ToString();
                        or.SuccBarCodes = bars;
                    }
                    else
                    {
                        ErrorResult er = new ErrorResult();
                        er.ErrorMsg = apiResult.Message;
                        er.BarCodes = bars;
                        or.ErrorInfo = er;
                    }
                    resultList.Add(or);
                    rsl.Result = true;
                    rsl.Data = resultList;
                    return rsl;
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 产成品入库
        /// </summary>
        /// <param name="tempDatas">扫描数据</param>
        /// <param name="usCode">提交人员信息</param>
        /// <returns></returns>
        public ReturnResult productInWare(List<DbTempScanData> tempDatas, string baseCode, string usCode)
        {
            rsl = new ReturnResult();
            StringBuilder sb = new StringBuilder();
            List<InOutResult> resultList = new List<InOutResult>();
            try
            {
                var pars = new Dictionary<string, object>();
                string msg = "";
                var paraData = this.wareOutData(tempDatas[0].tempCode, baseCode, ref msg);
                var data = (List<Dictionary<string, string>>)paraData["dataList"];
                var bars = (List<string>)paraData["barList"];
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                if (bars == null || bars.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取调用接口的数据条码";
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(usCode, baseCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                pars["System"] = sysPar;

                #region 构建参数
                pars["System"] = sysPar;
                #region 表头参数
                var head = new Dictionary<string, object>();
                head["ccode"] = DateTime.Now.ToString("yyyyMMddHHmmss");//单据号
                head["cwhcode"] = tempDatas[0].wareHouse;//发生仓库
                head["ddate"] = tempDatas[0].happenDate; //日期
                head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                head["ccuscode"] = "生产入库";//客户编码
                head["crdcode"] = tempDatas[0].typeCode;//发生类型
                head["cdepcode"] = tempDatas[0].operateDept;//发生部门
                pars["Head"] = head;
                #endregion

                #region 表体数据
                var cList = new List<Dictionary<string, object>>();
                for (int i = 0; i < data.Count; i++)
                {
                    var ldic = new Dictionary<string, object>();
                    ldic["irowno"] = data[i]["irow"].ToString();//行号
                    ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    ldic["cinvname"] = data[i]["proName"]; //存货名称，string类型
                    ldic["inum"] = data[i]["number"]; //件数
                    ldic["iquantity"] = data[i]["quantity"]; //数量（平米数），double类型
                    ldic["cdefine26"] = data[i]["weight"];//重量
                    ldic["cfree1"] = data[i]["xinghao"];//型号  
                    ldic["cfree2"] = data[i]["customerName"];//客户名称
                    ldic["cfree3"] = data[i]["meter"];//每件米数
                    ldic["cfree4"] = data[i]["xilie"];//系列
                    ldic["cbatch"] = data[i]["batch"];//批号
                    ldic["cposition"] = data[i]["goodsPosition"];//货位
                    cList.Add(ldic);
                }
                pars["List"] = cList;
                #endregion
                pars["isBlue"] = tempDatas[0].isBlue;//红蓝单
                #endregion
                //var url = Tools.ConfigReader.Reader["ProductInUrl"];
                string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "ProductIn");
                var postData = JsonConvert.SerializeObject(pars);

                msg = http.PostJson(url, postData);
                txt.AddLogMsg(string.Format("产成品入库,参数：{0},结果：{1}", postData, msg));

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl = JsonConvert.DeserializeObject<ReturnResult>(msg);
                    InOutResult or = new InOutResult();
                    if (rsl.Result)
                    {
                        or.SuccOrderCode = rsl.Data.ToString();
                        or.SuccBarCodes = bars;
                    }
                    else
                    {
                        ErrorResult er = new ErrorResult();
                        er.ErrorMsg = rsl.Message;
                        er.BarCodes = bars;
                        or.ErrorInfo = er;
                    }
                    resultList.Add(or);
                    rsl.Result = true;
                    rsl.Data = resultList;
                    return rsl;
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 其他入库
        /// </summary>
        /// <param name="tempDatas">扫描数据</param>
        /// <param name="usCode">提交人员信息</param>
        /// <returns></returns>
        public ReturnResult OtherInWareHouse(List<DbTempScanData> tempDatas, string baseName, string mCode)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(tempDatas[0].tempCode))
                {
                    rsl.Result = false;
                    rsl.Message = "传入的临时码为空";
                    return rsl;
                }
                var dic = new Dictionary<string, object>();
                List<string> tempCodes = new List<string>();
                tempCodes.Add(tempDatas[0].tempCode);
                dic.Add("tempCodes", tempCodes);
                dic.Add("dbName", baseName);
                var postData = JsonConvert.SerializeObject(dic);
                var url = Tools.ConfigReader.Reader["OtherInUrl"];
                var info = http.PostJson(url, postData);
                txt.AddLogMsg(string.Format("其他入库单,参数：{0},结果：{1}", postData, info));
                if (!string.IsNullOrWhiteSpace(info))
                {
                    return JsonConvert.DeserializeObject<ReturnResult>(info);
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 材料出库单
        /// </summary>
        /// <param name="tempDatas">扫描数据</param>
        /// <param name="usCode">提交人员信息</param>
        /// <returns></returns>
        public ReturnResult MaterialOutOrder(List<DbTempScanData> tempDatas, string baseCode, string usCode)
        {
            rsl = new ReturnResult();
            resultList = new List<InOutResult>();
            try
            {
                if (string.IsNullOrWhiteSpace(tempDatas[0].tempCode))
                {
                    rsl.Result = false;
                    rsl.Message = "传入的临时码为空";
                    return rsl;
                }
                txt.AddLogMsg("销售出库单开始执行");
                List<string> tempCodes = new List<string>();
                var pars = new Dictionary<string, object>();
                string msg = "";
                var paraData = this.wareOutData(tempDatas[0].tempCode, baseCode, ref msg);
                var data = (List<Dictionary<string, string>>)paraData["dataList"];
                var bars = (List<string>)paraData["barList"];
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                if (bars == null || bars.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取调用接口的数据条码";
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(usCode, baseCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                #region 构建参数
                pars["System"] = sysPar;
                #region 表头参数
                var head = new Dictionary<string, object>();
                head["ccode"] = DateTime.Now.ToString("yyyyMMddHHmmss");//单据号
                head["cwhcode"] = tempDatas[0].wareHouse;//发生仓库
                head["ddate"] = tempDatas[0].happenDate; //日期
                head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                head["crdcode"] = tempDatas[0].typeCode;//发生类型
                head["cdepcode"] = tempDatas[0].operateDept;//发生部门
                pars["Head"] = head;
                #endregion

                #region 表体数据
                var cList = new List<Dictionary<string, object>>();
                for (int i = 0; i < data.Count; i++)
                {
                    var ldic = new Dictionary<string, object>();
                    ldic["irowno"] = data[i]["irow"].ToString();//行号
                    ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    ldic["cinvname"] = data[i]["proName"]; //存货名称，string类型
                    ldic["inum"] = data[i]["number"]; //件数
                    ldic["iquantity"] = data[i]["quantity"]; //数量（平米数/重量），double类型
                    ldic["cdefine26"] = data[i]["weight"];//入库重量
                    ldic["cfree1"] = data[i]["xinghao"];//型号  
                    ldic["cfree2"] = data[i]["customer"];//客户
                    ldic["cfree3"] = data[i]["meter"];//每件米数
                    ldic["cfree4"] = data[i]["xilie"];//系列
                    ldic["cbatch"] = data[i]["batch"];//批号
                    ldic["cposition"] = data[i]["goodsPosition"];//货位
                    cList.Add(ldic);
                }
                pars["List"] = cList;
                #endregion
                pars["isBlue"] = tempDatas[0].isBlue;//红蓝单
                #endregion

                var postData = JsonConvert.SerializeObject(pars);
                //var url = Tools.ConfigReader.Reader["MaterialOutUrl"];
                string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "MatOut");
                msg = http.PostJson(url, postData);
                txt.AddLogMsg(string.Format("材料出库单,参数：{0},结果：{1}", postData, msg));

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl = JsonConvert.DeserializeObject<ReturnResult>(msg);
                    InOutResult or = new InOutResult();
                    if (rsl.Result)
                    {
                        or.SuccOrderCode = rsl.Data.ToString();
                        or.SuccBarCodes = bars;
                    }
                    else
                    {
                        ErrorResult er = new ErrorResult();
                        er.ErrorMsg = rsl.Message;
                        er.BarCodes = bars;
                        or.ErrorInfo = er;
                    }
                    resultList.Add(or);
                    rsl.Result = true;
                    rsl.Data = resultList;
                    return rsl;
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 销售出库
        /// </summary>
        /// <param name="tempDatas"></param>
        /// <param name="usCode"></param>
        /// <returns></returns>
        public ReturnResult SaleOutWareHouse(List<DbTempScanData> tempDatas, string baseCode, string usCode)
        {
            rsl = new ReturnResult();
            resultList = new List<InOutResult>();
            try
            {
                if (string.IsNullOrWhiteSpace(tempDatas[0].tempCode))
                {
                    rsl.Result = false;
                    rsl.Message = "传入的临时码为空";
                    return rsl;
                }
                txt.AddLogMsg("销售出库单开始执行");
                List<string> tempCodes = new List<string>();
                var pars = new Dictionary<string, object>();
                string msg = "";
                var paraData = this.wareOutData(tempDatas[0].tempCode, baseCode, ref msg);
                var data = (List<Dictionary<string, string>>)paraData["dataList"];
                var bars = (List<string>)paraData["barList"];
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                if (bars == null || bars.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取调用接口的数据条码";
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(usCode, baseCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                #region 构建参数
                pars["System"] = sysPar;
                #region 表头参数
                var dlid = "";
                var head = new Dictionary<string, object>();
                //head["ccode"] = DateTime.Now.ToString("yyyyMMddHHmmss");//单据号
                head["cwhcode"] = tempDatas[0].wareHouse;//发生仓库
                head["ddate"] = tempDatas[0].happenDate; //日期
                head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                head["ccuscode"] = tempDatas[0].customCode;//客户编码
                head["crdcode"] = tempDatas[0].typeCode;//发生类型
                head["cdepcode"] = tempDatas[0].operateDept;//发生部门
                var listDic = getDisPatchList(tempDatas[0].outOrderCode, baseCode, ref dlid);
                if (listDic == null || listDic.Count < 1)
                {
                    rsl.Message = "未获取发货单信息";
                    return rsl;
                }
                head["cbustype"] = "普通销售";
                if (!string.IsNullOrWhiteSpace(listDic[0]["cSBVCode"]))
                {
                    head["cbuscode"] = listDic[0]["cSBVCode"];//关联的发票号
                    head["csource"] = "普通发票";
                    var SBVID = "";//发票主表id
                    getSalebillVouch(listDic[0]["cSBVCode"], baseCode, ref SBVID);
                    head["cbillcode"] = SBVID;
                }
                else
                {
                    head["cbuscode"] = tempDatas[0].outOrderCode;//关联的发货单
                    if (listDic[0]["cBusType"].ToString().Equals("委托代销"))
                    {
                        head["cbustype"] = "委托代销";
                        head["csource"] = "委托代销";
                    }
                    else
                    {
                        head["csource"] = "发货单";
                    }
                }
                head["cdlcode"] = dlid;//发货单主表id
                head["cstcode"] = listDic[0]["cSTCode"];
                head["brdflag"] = "0";
                head["cvouchtype"] = "32";
                head["vt_id"] = "87";
                head["cdepcode"] = tempDatas[0].operateDept;//发生部门
                head["chandler"] = sysPar["sUserName"].ToString();
                head["dveridate"] = tempDatas[0].happenDate;
                pars["Head"] = head;
                #endregion

                #region 表体数据
                var cList = new List<Dictionary<string, object>>();
                for (int i = 0; i < data.Count; i++)
                {
                    var ldic = new Dictionary<string, object>();
                    ldic["irowno"] = data[i]["irow"].ToString();//行号
                    ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    //ldic["cinvname"] = data[i]["proName"]; //存货名称，string类型
                    ldic["iquantity"] = data[i]["quantity"]; //数量（平米数），double类型
                    if (!string.IsNullOrWhiteSpace(data[i]["cUnit"]))
                    {
                        ldic["inum"] = data[i]["number"]; //件数
                    }
                    //ldic["cdefine26"] = data[i]["weight"];//重量
                    ldic["cfree1"] = data[i]["color"];//颜色
                    ldic["cfree2"] = data[i]["guohao"];//锅号
                    ldic["cfree3"] = data[i]["shangbiao"];//商标
                    ldic["cfree4"] = data[i]["baozhuang"];//存放方式/包装
                    //ldic["cDefine22"] = data[i]["baozhuang"];//供应商
                    //ldic["cdefine23"] = data[i]["xianggui"];//图强箱规
                    ldic["cposition"] = data[i]["goodsPosition"];//货位
                    ldic["isodid"] = data[i]["isodid"];
                    ldic["iorderdid"] = data[i]["iorderdid"];
                    ldic["idlsid"] = data[i]["idlsid"];
                    ldic["bneedbill"] = "1";//是否需要开票,直接写库时必须传输
                    ldic["bCosting"] = "1";//单据是否核算，直接写库是必须传输，否则会提示不是库存生成无法删除
                    if (!string.IsNullOrWhiteSpace(data[i]["goodsPosition"]))
                    {
                        ldic["iposflag"] = "1";//是否货位管理
                    }
                    cList.Add(ldic);
                }
                pars["List"] = cList;
                #endregion
                pars["isBlue"] = tempDatas[0].isBlue;//红蓝单
                #endregion

                var postData = JsonConvert.SerializeObject(pars);
                //var url = Tools.ConfigReader.Reader["SaleOutUrl"];
                string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "SaleOutDirect");
                //string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "SaleOut");
                txt.AddLogMsg("传入接口的数据" + url + "\n" + postData);
                msg = http.PostJson(url, postData);
                txt.AddLogMsg(string.Format("销售出库单,参数：{0},结果：{1}", postData, msg));
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl = JsonConvert.DeserializeObject<ReturnResult>(msg);
                    InOutResult or = new InOutResult();
                    if (rsl.Result)
                    {
                        or.SuccOrderCode = rsl.Data.ToString();
                        or.SuccBarCodes = bars;
                    }
                    else
                    {
                        ErrorResult er = new ErrorResult();
                        er.ErrorMsg = rsl.Message;
                        er.BarCodes = bars;
                        or.ErrorInfo = er;
                    }
                    resultList.Add(or);
                    rsl.Result = true;
                    rsl.Data = resultList;
                    return rsl;
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }


        public ReturnResult NewSaleOutWareHouse(List<DbTempScanData> tempCode, string baseCode, string mCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select t.*,b.proCode,b.c_tssx,b.c_gongjin gongjin,isnull(c_mishu,'') mishu,b.unit");
                sb.Append(" from bar_TempScanData_info t inner join V_BarCode_Info b on t.barCode=b.barCode");
                sb.Append("where tempCpde='" + tempCode + "'");
                var bars = cmd.GetDataTable(sb.ToString());
                if (bars.Rows.Count > 0)
                {
                    rsl.Message = "没有条码数据";
                    return rsl;
                }
                List<string> rList = new List<string>();
                foreach (DataRow r in bars.Rows)
                {
                    string rowId = r["happenDate"].ToString();
                    string orCode = r["outOrderCode"].ToString();//发货单号
                    string nCode = string.Format("{0}-{1}", rowId, orCode);
                    if (rList.Contains(nCode))
                    {
                        double mNum = 0, cNum = 0;
                        int jianshu = 0;
                        var dr = bars.Select("happenDate='" + rowId + "' and outOrderCode='" + orCode + "'");
                        foreach (DataRow drow in dr)
                        {
                            mNum += double.Parse(drow["gongjin"].ToString());
                            if (!string.IsNullOrWhiteSpace(drow["mishu"].ToString()))
                            {
                                cNum += double.Parse(drow["mishu"].ToString());
                            }
                        }
                        sb.Clear();
                        sb.Append("select * from DispatchList where cDLCode='" + orCode + "' and ");
                        sb.Append("DLID='" + rowId + "'");
                        var u8OrTable = cuHelper.getData(sb.ToString(), baseCode);
                        if (u8OrTable.Rows.Count > 0)
                        {
                            sb.Clear();
                            string orNumer = u8OrTable.Rows[0][""].ToString();
                        }
                    }
                }
                #region 旧代码
                //var singleSheetList = new List<ViewTempData>();
                //var tinyGroup = tempDatas.GroupBy(x => new { x.proCode, x.cTssx });
                //foreach (var ig in tinyGroup)
                //{
                //    var igFirst = ig.FirstOrDefault();
                //    //件数
                //    igFirst.numberAvoidNull = ig.Sum(
                //        x => decimal.Parse(x.numberAvoidNull)
                //            ).ToString();
                //    //重量
                //    igFirst.number = ig.Sum(
                //        x => decimal.Parse(x.number)
                //            ).ToString();
                //    //米数/个
                //    igFirst.meter = ig.Sum(
                //       x => decimal.Parse(x.meter)
                //           ).ToString();
                //    singleSheetList.Add(igFirst);
                //}
                //#region 获取未审核的发货单数据
                //sb.Clear();
                //sb.Append("select dts.AutoID,dt.cDLCode,dts.iQuantity,dts.cInvCode, ");
                //sb.Append(" dts.inum,isnull(dts.cDefine22,'0') cDefine22,isnull(dts.cFree7,'') cFree7 ");
                //sb.Append(" from DispatchList dt ");
                //sb.Append(" inner join DispatchLists dts on dt.DLID =dts.DLID ");
                //sb.Append(" where dt.cDLCode='" + tempDatas[0].outOrderCode + "'");
                //sb.Append(" and isnull(dt.cVerifier,'') ='' and isnull(dt.dverifydate,'') ='' ");
                //var disTable = cuHelper.getData(sb.ToString(), baseCode);
                //if (disTable.Rows.Count < 1)
                //{
                //    rsl.Result = false;
                //    rsl.Message = "未获得发货单数据";
                //    return rsl;
                //}
                //#endregion
                //var U8OrderCode = string.Empty;
                //U8OrderCode =tempDatas[0].outOrderCode;
                //#region 循环遍历扫描的数据并创建修改语句
                //List<string> sqlList = new List<string>();
                //foreach (var vData in singleSheetList)
                //{
                //    #region 判断存货的主计量单位
                //    var iquantity = "0";//主计量数量
                //    var inum = "0";//辅助计量数量
                //    switch (vData.mUnitName)
                //    {
                //        case "公斤":
                //            iquantity = vData.isBlue == "1" ?
                //        "" + vData.number : "-" + vData.number;
                //            inum = vData.isBlue == "1" ?
                //       "" + vData.meter : "-" + vData.meter;
                //            break;
                //        case "个":
                //            iquantity = vData.isBlue == "1" ?
                //         "" + vData.meter : "-" + vData.meter;
                //            inum = vData.isBlue == "1" ?
                //       "" + vData.number : "-" + vData.number;
                //            break;
                //    }
                //    #endregion
                //    //自定义项（件数）
                //    var number = vData.isBlue == "1" ?
                //        "" + vData.numberAvoidNull : "-" + vData.numberAvoidNull;

                //    //var disLength = disTable.Select("cInvCode='" + vData.proCode + "'");
                //    var disLength = disTable.Select("cInvCode='" + vData.proCode + "' and cFree7='" + vData.cTssx + "'");
                //    if (disLength.Length > 0)
                //    {
                //        rsl = getNumberMCode(tempDatas[0].outOrderCode, baseCode);
                //        if (rsl.Result)
                //        {
                //            if (!string.IsNullOrWhiteSpace(rsl.Data.ToString()) && double.Parse(rsl.Data.ToString()) > 0)
                //            {
                //                iquantity = (Convert.ToDecimal(iquantity) + Convert.ToDecimal(disLength[0]["iQuantity"].ToString())).ToString();
                //                inum = (Convert.ToDecimal(inum) + Convert.ToDecimal(disLength[0]["inum"].ToString())).ToString();
                //                number = (Convert.ToDecimal(number) + Convert.ToDecimal(disLength[0]["cDefine22"].ToString())).ToString();
                //            }
                //            //计算主计量与辅助计量单位的换算率(主计量数量/辅助计量数量)
                //            //如果是不加换算率后期销售发票是无法带出辅助单位数量的
                //            var iInvExchRate = "0";
                //            iInvExchRate = (Convert.ToDecimal(iquantity) / Convert.ToDecimal(inum)).ToString("F2");
                //            Dictionary<string, string> dic = new Dictionary<string, string>();
                //            dic.Add("iquantity", iquantity);
                //            dic.Add("inum", inum);
                //            dic.Add("cDefine22", number);
                //            dic.Add("iInvExchRate", iInvExchRate);
                //            dic.Add("AutoID", disLength[0]["AutoID"].ToString());
                //            txt.AddLogMsg("传入U8的数据" + JsonConvert.SerializeObject(dic));
                //            sb.Clear();
                //            sb.Append(" update DispatchLists set iQuantity='" + iquantity + "',");
                //            sb.Append(" inum='" + inum + "',cDefine22='" + number + "',");
                //            sb.Append(" iInvExchRate='" + iInvExchRate + "'");
                //            sb.Append(" where AutoID=" + disLength[0]["AutoID"] + "");
                //            sqlList.Add(sb.ToString());
                //        }
                //    }
                //}

                //#endregion
                //if (sqlList.Count > 0)
                //{
                //    rsl = cuHelper.TransUpdate(sqlList, null,baseCode);
                //    txt.AddLogMsg(rsl.Result.ToString());
                //    if (rsl.Result)
                //    {
                //        //修改成功后返回修改的发货单号
                //        rsl.Data = U8OrderCode;
                //        txt.AddLogMsg("发货单修改成功:单号为" + U8OrderCode);
                //    }
                //}
                #endregion
            }
            catch (Exception ex)
            {

            }
            return rsl;
        }
        /// <summary>
        /// 分切其他出库
        /// </summary>
        /// <param name="tempDatas"></param>
        /// <param name="usCode"></param>
        /// <returns></returns>
        public ReturnResult CutOtherOut(Dictionary<string, object> paraData, string baseCode, string usCode)
        {
            rsl = new ReturnResult();
            try
            {
                if (paraData == null || paraData.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "传入的临时数据为空";
                    return rsl;
                }

                var pars = new Dictionary<string, object>();
                string msg = "";
                msg = "";
                var sysPar = this.createUserPar(usCode, baseCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }

                //var paraData = this.wareOutData(tempDatas[0].tempCode, baseCode, ref msg);
                foreach (var key in paraData.Keys)
                {
                    var tempData = (Dictionary<string, object>)paraData[key];
                    var data = (List<Dictionary<string, string>>)tempData["dataList"];
                    var bars = (List<string>)tempData["barList"];
                    if (bars == null || bars.Count <= 0)
                    {
                        rsl.Result = false;
                        rsl.Message = "没有获取调用接口的数据条码";
                        return rsl;
                    }

                    #region 构建参数
                    pars["System"] = sysPar;
                    #region 表头参数
                    var head = new Dictionary<string, object>();
                    head["ccode"] = DateTime.Now.ToString("yyyyMMddHHmmss");//单据号
                    head["cwhcode"] = data[0]["wareHouse"].ToString();//发生仓库
                    head["ddate"] = getNowDate(); //日期
                    head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                    head["crdcode"] = data[0]["typeCode"].ToString();//发生类型
                    head["cdepcode"] = data[0]["deptCode"].ToString();//发生部门
                    pars["Head"] = head;
                    #endregion

                    #region 表体数据
                    var cList = new List<Dictionary<string, object>>();
                    int irow = 0;
                    for (int i = 0; i < data.Count; i++)
                    {
                        irow++;
                        var ldic = new Dictionary<string, object>();
                        ldic["irowno"] = irow;//行号
                        ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                        ldic["iquantity"] = data[i]["quantity"]; //数量（平米数），double类型
                        ldic["inum"] = data[i]["number"]; //件数
                        ldic["cdefine26"] = data[i]["weight"];//重量
                        ldic["cfree1"] = data[i]["xinghao"];//型号  
                                                            //ldic["cfree2"] = data[i]["customer"];//客户
                        ldic["cfree3"] = data[i]["meter"];//每件米数
                        ldic["cfree4"] = data[i]["xilie"];//系列
                        ldic["cbatch"] = data[i]["batch"];//批号
                        ldic["cposition"] = data[i]["goodsPosition"];//货位
                        cList.Add(ldic);
                    }
                    pars["List"] = cList;
                    #endregion
                    pars["isBlue"] = data[0]["isBlue"].ToString();
                    #endregion

                    string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "OtherOut");
                    var postData = JsonConvert.SerializeObject(pars);
                    msg = http.PostJson(url, postData);
                    txt.AddLogMsg(string.Format("其它出库单,参数：{0},结果：{1}", postData, msg));
                    if (!string.IsNullOrWhiteSpace(msg))
                    {
                        rsl = JsonConvert.DeserializeObject<ReturnResult>(msg);
                        InOutResult or = new InOutResult();
                        if (rsl.Result)
                        {
                            or.SuccOrderCode = rsl.Data.ToString();
                            or.SuccBarCodes = bars;
                        }
                        else
                        {
                            ErrorResult er = new ErrorResult();
                            er.ErrorMsg = rsl.Message;
                            er.BarCodes = bars;
                            or.ErrorInfo = er;
                        }
                        resultList.Add(or);
                    }
                    else
                    {
                        rsl.Message = "接口结果返回为空";
                    }
                }
                rsl.Result = true;
                rsl.Data = resultList;
                return rsl;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 销售发票
        /// </summary>
        /// <param name="tempDatas"></param>
        /// <param name="usCode"></param>
        /// <returns></returns>
        public ReturnResult SaleInvoice(List<DbTempScanData> tempDatas, string usCode)
        {
            rsl = new ReturnResult();
            try
            {
                var pars = new Dictionary<string, object>();
                string msg = "";
                var data = this.InvoiceData(tempDatas[0].tempCode, tempDatas[0].customCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(usCode, "", ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                pars["System"] = sysPar;

                #region 表头参数
                var head = new Dictionary<string, object>();
                head["ddate"] = tempDatas[0].happenDate; //开票日期
                head["cdepname"] = tempDatas[0].operateDept; //销售部门，string类型
                head["cstcode"] = "00"; //销售类型编号,默认普通销售(编码为00)
                head["cssname"] = "普通销售";//销售类型
                head["ccusabbname"] = tempDatas[0].customCode;//客户简称
                head["csscode"] = "10";//结算方式，默认现金(10)
                head["cssname"] = "现金";
                head["ccuscode"] = tempDatas[0].customCode; //客户编号
                head["cmaker"] = sysPar["sUserName"].ToString();
                head["cdepname"] = tempDatas[0].operateDept;//部门
                head["iexchrate"] = "1";//汇率
                head["csaleout"] = "";//出库单号
                head["csource"] = "销售";//单据来源
                head["csbvcode"] = "2021090010";
                pars["Head"] = head;
                #endregion

                #region 表体数据
                var cList = new List<Dictionary<string, object>>();
                for (int i = 0; i < data.Count; i++)
                {
                    var ldic = new Dictionary<string, object>();
                    ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    ldic["cinvname"] = data[i]["proName"]; //存货名称，string类型
                    ldic["iquantity"] = data[i]["weight"].ToString(); //数量，double类型
                    ldic["editprop"] = "A"; //编辑属性：A表新增，M表修改，D表删除，string类型
                    ldic["iunitprice"] = data[i]["price"]; //无税单价
                    //ldic["cmemo"] = "接口传递";
                    ldic["inum"] = data[i]["number"]; //件数
                    ldic["isum"] = Math.Round(double.Parse(data[i]["weight"].ToString()) * double.Parse(data[i]["price"].ToString()), 2);//价税合计
                    cList.Add(ldic);
                }
                pars["List"] = cList;
                #endregion
                pars["isBlue"] = "1";
                string url = Tools.ConfigReader.Reader["APIService"];
                U8API api = new U8API(url);
                var postData = JsonConvert.SerializeObject(pars);

                msg = api.CreateSaleInvoice(postData);
                txt.AddLogMsg(string.Format("销售发票,参数：{0},结果：{1}", postData, msg));
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    return JsonConvert.DeserializeObject<ReturnResult>(msg);
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 销售发票(不是长久之计)
        /// </summary>
        /// <param name="tempDatas"></param>
        /// <param name="usCode"></param>
        /// <returns></returns>
        public ReturnResult NewSaleInvoice(List<DbTempScanData> tempDatas, string usCode, string mCode)
        {
            rsl = new ReturnResult();
            try
            {
                string msg = "";
                var data = this.InvoiceData(tempDatas[0].tempCode, tempDatas[0].customCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(usCode, "", ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                Dictionary<string, object> pars = new Dictionary<string, object>();
                Dictionary<string, object> outPar = new Dictionary<string, object>();
                outPar["@efserverid"] = "EF_" + Tools.ConfigReader.Reader["sAccID"];
                outPar["@eftype"] = "13";//销售发票固定值
                outPar["@proc"] = "add";
                outPar["@efdebug"] = "0";
                outPar["@refcardnumber"] = "?";
                outPar["@succeed"] = "1";
                outPar["@dsc"] = "13处理成功!查询成功！";

                Dictionary<string, object> voucher = new Dictionary<string, object>();
                voucher["@cardnumber"] = "13";
                voucher["@ccardname"] = "";
                voucher["@xmlns:z"] = "EF";
                var head = new Dictionary<string, object>();
                var row = new Dictionary<string, object>();
                #region 表头赋值
                row["ivouchstate"] = "Opening";
                row["csysbarcode"] = "||SA72|2021090001";
                row["ivtid"] = "17";
                row["@ufts"] = "402.1977";
                row["@csource"] = "销售";
                row["@cstcode"] = "00";
                row["@cdepcode"] = "1";
                row["@ccuscode"] = tempDatas[0].customCode;
                row["@cstname"] = "普通销售";
                row["@ccusabbname"] = "";
                row["@ccusaddress"] = "";
                row["@ccusfax"] = "";
                row["@ccusbank"] = "";
                row["@ccusaccount"] = "";
                row["@ccusoaddress"] = "";
                row["@bcashsale"] = "0";
                row["@ccuspaycond"] = "";
                row["@ccusotype"] = "";
                row["@sbvid"] = "1000010911";
                //row["@csbvcode"] = "2021090001";//发票号
                row["@csbvcode"] = mCode;//发票号
                row["@cvouchtype"] = "27";
                row["@ddate"] = tempDatas[0].happenDate;
                row["@cmaker"] = sysPar["sUserName"].ToString();
                row["@cdepname"] = tempDatas[0].deptName;
                row["@iexchrate"] = "1";
                row["@itaxrate"] = "0";
                row["@breturnflag"] = "0";
                row["@bfirst"] = "False";
                row["@cbustype"] = "普通销售";
                row["@cexch_name"] = "人民币";
                row["@ccusregcode"] = "";
                row["@icuscreline"] = "0";
                row["@iarmoney"] = "";
                row["@ccusname"] = "";
                row["@clastcusname"] = "";
                row["@idisp"] = "0";
                row["@ccusdefine1"] = "";
                row["@ccusdefine2"] = "";
                row["@ccusdefine3"] = "";
                row["@cauthid"] = "";
                row["@cpayment"] = "否";
                row["@cvouchtype2"] = "27";
                row["@cvouchname"] = "27";
                row["@ccccode"] = "1001";
                row["@ccushand"] = "";
                row["@ccusphone"] = "";
                row["@bcredit"] = "否";
                row["@itaxbillstate"] = "0";
                row["@ccustomerphone"] = "";
                row["@ccreditcuscode"] = "";
                row["@ccreditcusname"] = "";
                row["@ioutgolden"] = "0";
                row["@iverifystate"] = "0";
                row["@iswfcontrolled"] = "0";
                row["@dcreatesystime"] = getNow();
                row["@iprintcount"] = "0";
                row["@bnottogoldtax"] = "0";
                row["@cgoldtaxcusname"] = "";
                row["@isumdx"] = "";
                row["@isumx"] = "1";
                row["@zdsumdx"] = "";
                row["@zdsum"] = "1";
                #endregion
                head["z:row"] = row;
                voucher["head"] = head;
                var body = new Dictionary<string, object>();
                row = new Dictionary<string, object>();
                List<Dictionary<string, object>> rowList = new List<Dictionary<string, object>>();
                int i = 0;
                foreach (var dic in data)
                {
                    i++;
                    row = new Dictionary<string, object>();
                    #region
                    row["@cwhname"] = "";
                    row["@cinvcode"] = dic["proCode"];
                    row["@cinvname"] = dic["proName"];
                    row["@cinvaddcode"] = "01001";
                    row["@cwhcode"] = tempDatas[0].wareHouse;
                    row["@cinvm_unit"] = "kg";
                    row["@igrouptype"] = "0";
                    row["@cgroupcode"] = "0000000000";
                    row["@irowno"] = i++;
                    row["@bservice"] = "False";
                    row["@iquantity"] = dic["weight"];
                    row["@iunitprice"] = dic["price"];
                    row["@imoney"] = "1";
                    row["@itax"] = "0";
                    double sum = double.Parse(dic["weight"]) * double.Parse(dic["price"]);
                    row["@isum"] = sum.ToString();
                    row["@idiscount"] = "0";
                    row["@isbvid"] = "";//原销售订单标识，设置成空，否则传入的单据不能修改
                    row["@sbvid"] = "1000010911";
                    row["@iquotedprice"] = "0";
                    row["@autoid"] = "1000034256";
                    row["@inatunitprice"] = dic["price"];
                    row["@inatmoney"] = "1";
                    row["@inattax"] = "0";
                    row["@inatsum"] = sum.ToString();
                    row["@inatdiscount"] = "0";
                    row["@imoneysum"] = "0";
                    row["@iexchsum"] = "0";
                    row["@itaxunitprice"] = dic["price"];
                    row["@bsettleall"] = "False";
                    row["@binvbatch"] = "False";
                    row["@cwhvaluestyle"] = "全月平均法";
                    row["@bfree1"] = "False";
                    row["@bfree2"] = "False";
                    row["@bfree3"] = "False";
                    row["@bfree4"] = "False";
                    row["@bfree5"] = "False";
                    row["@bfree6"] = "False";
                    row["@bfree7"] = "False";
                    row["@bfree8"] = "False";
                    row["@bfree9"] = "False";
                    row["@bfree10"] = "False";
                    row["@bsalepricefree1"] = "False";
                    row["@bsalepricefree2"] = "False";
                    row["@bsalepricefree3"] = "False";
                    row["@bsalepricefree4"] = "False";
                    row["@bsalepricefree5"] = "False";
                    row["@bsalepricefree6"] = "False";
                    row["@bsalepricefree7"] = "False";
                    row["@bsalepricefree8"] = "False";
                    row["@bsalepricefree9"] = "False";
                    row["@bsalepricefree10"] = "False";
                    row["@bbatchcreate"] = "False";
                    row["@bbatchproperty1"] = "False";
                    row["@bbatchproperty2"] = "False";
                    row["@bbatchproperty3"] = "False";
                    row["@bbatchproperty4"] = "False";
                    row["@bbatchproperty5"] = "False";
                    row["@bbatchproperty6"] = "False";
                    row["@bbatchproperty7"] = "False";
                    row["@bbatchproperty8"] = "False";
                    row["@bbatchproperty9"] = "False";
                    row["@bbatchproperty10"] = "False";
                    row["@kl"] = "100";
                    row["@kl2"] = "100";
                    row["@binvtype"] = "False";
                    row["@itb"] = "正常";
                    row["@binvquality"] = "False";
                    row["@cmassunit"] = "";
                    row["@itaxrate"] = "0";
                    row["@dkl1"] = "0";
                    row["@dkl2"] = "0";
                    row["@cbsysbarcode"] = "||SA72|2021090001|1";
                    row["@fsalecost"] = "0";
                    row["@fsaleprice"] = "0";
                    row["@cinvccode"] = "01";
                    row["@btrack"] = "False";
                    row["@bgsp"] = "否";
                    row["@ccomunitcode"] = "0000000003";
                    row["@btracksalebill"] = "0";
                    row["@batomodel"] = "否";
                    row["@bptomodel"] = "否";
                    row["@bqaneedcheck"] = "否";
                    row["@bqaurgency"] = "否";
                    row["@iinvncost"] = "16";
                    row["@fcusminprice"] = ".000000000";
                    row["@binvmodel"] = "否";
                    row["@csrpolicy"] = "PE";
                    row["@bneedsign"] = "0";
                    row["@bcosting"] = "True";
                    row["@bgift"] = "0";
                    row["@bsaleprice"] = "0";
                    row["@autoid2"] = "1000034256";
                    row["@bproxywh"] = "False";
                    row["@bserial"] = "0";
                    row["@bmpforderclosed"] = "0";
                    row["@fretailrealamount"] = ".000000000";
                    row["@fretailapportionamount"] = ".000000000";
                    row["@fretailsettleamount"] = ".000000000";
                    row["@isaconmode"] = "0";
                    row["@editprop"] = "";
                    #endregion
                    rowList.Add(row);
                }
                body["z:row"] = row;
                voucher["body"] = body;
                outPar["voucher"] = voucher;//表单内容
                pars["ufinterface"] = outPar;
                HttpAgreement h = new HttpAgreement();
                string s = JsonConvert.SerializeObject(pars);
                var result = h.PostJson(Tools.ConfigReader.Reader["EFAPI"], s);
                var json = JsonConvert.DeserializeObject<JObject>(result);
                if (json["ufinterface"]["@dsc"].ToString().Contains("处理成功"))
                {
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = result;
                    txt.AddLogMsg("新销售发票接口返回错误：" + result);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 调拨单
        /// 移动端出入库使用
        /// </summary>
        /// <param name="tempDatas"></param>
        /// <param name="usCode"></param>
        /// <returns></returns>
        public ReturnResult WareHouseChanage(List<DbTempScanData> tempDatas, string baseCode, string usCode,ref string posCode,string iscar=null)
        {
            rsl = new ReturnResult();
            try
            {
                var pars = new Dictionary<string, object>();
                string msg = "";
                var paraData = new Dictionary<string,object>();
                if (string.IsNullOrEmpty(iscar))
                {
                    paraData = this.wareOutData(tempDatas[0].tempCode, baseCode, ref msg);
                }
                else
                {
                    paraData = this.carOutData(tempDatas[0].tempCode, baseCode, ref msg); 
                }
                //var paraData = this.wareOutData(tempDatas[0].tempCode, baseCode, ref msg);
                var data = (List<Dictionary<string, string>>)paraData["dataList"];
                var bars = (List<string>)paraData["barList"];
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                if (bars == null || bars.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取调用接口的数据条码";
                    return rsl;
                }
                msg = "";
                var sysPar = this.createUserPar(usCode, baseCode, ref msg);
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl.Message = msg;
                    return rsl;
                }
                pars["System"] = sysPar;
                #region 调拨单表头参数
                var head = new Dictionary<string, object>();
                head["dtvdate"] = tempDatas[0].happenDate; //日期
                head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                head["ciwhcode"] = tempDatas[0].targetWareHouse; //转入仓库
                head["cowhcode"] = tempDatas[0].wareHouse;//转出仓库
                head["cordcode"] = tempDatas[0].typeCode;//发生/出库类型
                head["cirdcode"] = tempDatas[0].targetTypeCode;//目标/入库类型
                //head["cidepcode"] = tempDatas[0].operateDept;//发生部门
                //head["ctvcode"] = DateTime.Now.ToString("yyyyMMddHHmmss");
                head["cverifyperson"] = sysPar["sUserName"].ToString();
                head["dverifydate"] = tempDatas[0].happenDate;
                head["vt_id"] = "89";
                pars["Head"] = head;
                #region 其他出库表头数据
                var rd09head = new Dictionary<string, object>();
                rd09head["dDate"] = tempDatas[0].happenDate; //日期
                rd09head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                rd09head["cWhCode"] = tempDatas[0].wareHouse;//转出仓库
                rd09head["crdcode"] = tempDatas[0].typeCode;//发生/出库类型
                rd09head["vt_id"] = "131389";
                rd09head["brdflag"] = "0";
                rd09head["cvouchtype"] = "09";
                rd09head["cbustype"] = "调拨出库";
                rd09head["csource"] = "调拨";
                rd09head["btransflag"] = "0";
                pars["rd09Head"] = rd09head;
                #endregion
                #region 其他入库表头数据
                var rd08head = new Dictionary<string, object>();
                rd08head["dDate"] = tempDatas[0].happenDate; //日期
                rd08head["cmaker"] = sysPar["sUserName"].ToString();//制单人
                rd08head["cWhCode"] = tempDatas[0].targetWareHouse; //转入仓库
                rd08head["crdcode"] = tempDatas[0].targetTypeCode;//目标/入库类型
                rd08head["vt_id"] = "8164";
                rd08head["brdflag"] = "1";
                rd08head["cvouchtype"] = "08";
                rd08head["cBusType"] = "调拨入库";
                rd08head["cSource"] = "调拨";
                rd09head["btransflag"] = "0";
                rd09head["csourcels"] = "1";
                pars["rd08Head"] = rd08head;
                #endregion
                #endregion

                #region 表体数据
                var cList = new List<Dictionary<string, object>>();
                var rd09cList = new List<Dictionary<string, object>>();
                var rd08cList = new List<Dictionary<string, object>>();

                var HasGetPosCode = false;

                for (int i = 0; i < data.Count; i++)
                {
                    var ldic = new Dictionary<string, object>();
                    ldic["irowno"] = data[i]["irow"]; //行号
                    ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    //ldic["cinvname"] = data[i]["proName"]; //存货名称，string类型
                    if (!string.IsNullOrWhiteSpace(data[i]["cUnit"]))
                    {
                        ldic["itvnum"] = data[i]["number"]; //件数
                    }
                    ldic["itvquantity"] = data[i]["quantity"].ToString(); //数量，double类型
                    //ldic["cinvm_unit"] = data[i]["mUnit"];//主计量单位
                    ldic["cfree1"] = data[i]["color"];//颜色
                    ldic["cfree2"] = data[i]["guohao"];//锅号
                    ldic["cfree3"] = data[i]["shangbiao"];//商标
                    ldic["cfree4"] = data[i]["baozhuang"];//存放方式/包装
                    //ldic["cDefine22"] = data[i]["baozhuang"];//供应商
                    //ldic["cdefine23"] = data[i]["xianggui"];//图强箱规
                    ldic["cinposcode"] = data[i]["targetGoodsPosition"];//调入货位
                    ldic["coutposcode"] = data[i]["goodsPosition"];//调出货位
                    
                    if (!HasGetPosCode)
                    {
                        posCode = data[i]["targetGoodsPosition"];
                        HasGetPosCode = true;
                    }

                    cList.Add(ldic);
                    #region 其他出库子表数据
                    var rd09ldic = new Dictionary<string, object>();
                    rd09ldic["irowno"] = data[i]["irow"]; //行号
                    rd09ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    if (!string.IsNullOrWhiteSpace(data[i]["cUnit"]))
                    {
                        rd09ldic["inum"] = data[i]["number"]; //件数
                    }
                    rd09ldic["iquantity"] = data[i]["quantity"].ToString(); //数量，double类型
                    rd09ldic["inquantity"] = data[i]["quantity"].ToString(); //数量，double类型
                    //ldic["cinvm_unit"] = data[i]["mUnit"];//主计量单位
                    rd09ldic["cfree1"] = data[i]["color"];//颜色
                    rd09ldic["cfree2"] = data[i]["guohao"];//锅号
                    rd09ldic["cfree3"] = data[i]["shangbiao"];//商标
                    rd09ldic["cfree4"] = data[i]["baozhuang"];//存放方式/包装
                    //ldic["cDefine22"] = data[i]["baozhuang"];//供应商
                    //ldic["cdefine23"] = data[i]["xianggui"];//图强箱规
                    rd09ldic["cposition"] = data[i]["goodsPosition"];//调出货位
                    if (!string.IsNullOrWhiteSpace(data[i]["goodsPosition"]))
                    {
                        rd09ldic["iposflag"] = "1";//是否货位管理
                    }
                    if (!string.IsNullOrWhiteSpace(data[i]["quantity"].ToString()) && Convert.ToDecimal(data[i]["quantity"].ToString()) > 0)
                    {
                        rd09ldic["bcosting"] = "1";//单据是否核算
                    }
                    rd09cList.Add(rd09ldic);
                    #endregion
                    #region 其他入库子表数据
                    var rd08ldic = new Dictionary<string, object>();
                    rd08ldic["irowno"] = data[i]["irow"]; //行号
                    rd08ldic["cinvcode"] = data[i]["proCode"]; //存货编码，string类型
                    if (!string.IsNullOrWhiteSpace(data[i]["cUnit"]))
                    {
                        rd08ldic["inum"] = data[i]["number"]; //件数
                    }
                    rd08ldic["iquantity"] = data[i]["quantity"].ToString(); //数量，double类型
                    rd08ldic["inquantity"] = data[i]["quantity"].ToString(); //数量，double类型
                    //ldic["cinvm_unit"] = data[i]["mUnit"];//主计量单位
                    rd08ldic["cfree1"] = data[i]["color"];//颜色
                    rd08ldic["cfree2"] = data[i]["guohao"];//锅号
                    rd08ldic["cfree3"] = data[i]["shangbiao"];//商标
                    rd08ldic["cfree4"] = data[i]["baozhuang"];//存放方式/包装
                    //ldic["cDefine22"] = data[i]["baozhuang"];//供应商
                    //ldic["cdefine23"] = data[i]["xianggui"];//图强箱规
                    rd08ldic["cposition"] = data[i]["targetGoodsPosition"];//调入货位
                    if (!string.IsNullOrWhiteSpace(data[i]["targetGoodsPosition"])) {
                        rd08ldic["iposflag"] = "1";//是否货位管理
                    }
                    if (!string.IsNullOrWhiteSpace(data[i]["quantity"].ToString())&&Convert.ToDecimal(data[i]["quantity"].ToString())>0) {
                        rd08ldic["bcosting"] = "1";//单据是否核算
                    }
                    rd08cList.Add(rd08ldic);
                    #endregion
                }
                pars["List"] = cList;
                pars["rd09List"] = rd09cList;
                pars["rd08List"] = rd08cList;
                #endregion
                pars["isBlue"] = "1";

                string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "TransVouchDirect");
                var postData = JsonConvert.SerializeObject(pars);
                txt.AddLogMsg(string.Format("调拨出入参数,参数：{0}", postData));
                msg = http.PostJson(url, postData);
                txt.AddLogMsg(string.Format("调拨出入参数,参数：{0},结果：{1}", postData, msg));
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    rsl = JsonConvert.DeserializeObject<ReturnResult>(msg);
                    InOutResult or = new InOutResult();
                    if (rsl.Result)
                    {
                        or.SuccOrderCode = rsl.Data.ToString();
                        or.SuccBarCodes = bars;
                        rsl.Result = true;
                    }
                    else
                    {
                        ErrorResult er = new ErrorResult();
                        er.ErrorMsg = rsl.Message;
                        er.BarCodes = bars;
                        or.ErrorInfo = er;
                    }
                    resultList.Add(or);
                    rsl.Data = resultList;
                    return rsl;
                }
                else
                {
                    rsl.Message = "接口结果返回为空";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 货位调整单
        /// </summary>
        /// <param name="tempDatas"></param>
        /// <param name="usCode"></param>
        /// <returns></returns>
        //public ReturnResult GoodsPositionChanage(string json, string baseCode, string usCode)
        //{
        //    rsl = new ReturnResult();
        //    try
        //    {
        //        var pars = new Dictionary<string, object>();
        //        string msg = "";

        //        #region  移车信息
        //        var transWrapper = JsonConvert.DeserializeObject<TransferCartWrapper>(json);   //装卸车信息

        //        var fromCartCode = transWrapper.fromCart; //卸
        //        var wp = this.getCarsHousePosition(fromCartCode, ref msg);  //仓库 货位
        //        var wareHouse = wp.Split(',')[0];  //仓库
        //        var goodsPosition = wp.Split(',')[1];  //货位
        //        if (!string.IsNullOrWhiteSpace(msg))
        //        {
        //            rsl.Message = msg;
        //            return rsl;
        //        }

        //        var toCartCode = transWrapper.toCart;  //装
        //        wp = this.getCarsHousePosition(toCartCode, ref msg);
        //        var targetGoodsPosition = wp.Split(',')[1];  //目标货位
        //        if (!string.IsNullOrWhiteSpace(msg))
        //        {
        //            rsl.Message = msg;
        //            return rsl;
        //        }

        //        var cards = transWrapper.invCards;
        //        if (cards.Count <= 0)
        //        {
        //            rsl.Message = "未获取到转移存货信息";
        //            return rsl;
        //        }
        //        #endregion

        //        var sysPar = this.createUserPar(usCode, baseCode, ref msg);
        //        if (!string.IsNullOrWhiteSpace(msg))
        //        {
        //            rsl.Message = msg;
        //            return rsl;
        //        }
        //        #region 构建参数
        //        pars["System"] = sysPar;
        //        #region 表头参数
        //        var head = new Dictionary<string, object>();
        //        head["cwhcode"] = wareHouse;//发生仓库
        //        head["ddate"] = DateTime.Now.ToString("yyyy-MM-dd"); //日期
        //        head["cmaker"] = sysPar["sUserName"].ToString();//制单人
        //       // head["cdepcode"] = tempDatas[0].operateDept;//发生部门
        //        head["dnmaketime"] = DateTime.Now.ToString("yyyy-MM-dd HH:ss:mm");
        //        pars["Head"] = head;
        //        #endregion

        //        #region 表体数据
        //        var cList = new List<Dictionary<string, object>>();
        //        for (int i = 0; i < cards.Count; i++)
        //        {
        //            var ldic = new Dictionary<string, object>();
        //            ldic["irowno"] = i+1;//行号
        //            ldic["cinvcode"] = cards[i].proCode; //存货编码，string类型
        //            ldic["iquantity"] = cards[i].number; //数量，double类型
        //            ldic["cbposcode"] = goodsPosition;//调整前货位
        //            ldic["caposcode"] = targetGoodsPosition;//调整后货位
        //            ldic["cFree1"] = cards[i].proColor;//颜色  
        //            ldic["cFree3"] = cards[i].brand;//商标
        //            ldic["iExpiratDateCalcu"] = "0";
        //            cList.Add(ldic);
        //        }
        //        pars["List"] = cList;
        //        #endregion



        //        #endregion

        //        string url = string.Format("{0}{1}", Tools.ConfigReader.Reader["APIUrl"], "AdjustPostion");
        //        var postData = JsonConvert.SerializeObject(pars);
        //        msg = http.PostJson(url, postData);
        //        txt.AddLogMsg(string.Format("货位调整参数,参数：{0},结果：{1}", postData, msg));
        //        if (!string.IsNullOrWhiteSpace(msg))
        //        {
        //            rsl = JsonConvert.DeserializeObject<ReturnResult>(msg);
        //        }
        //        else
        //        {
        //            rsl.Message = "接口结果返回为空";
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        rsl.Message = ex.Message;
        //    }
        //    return rsl;
        //}

        ///获取工装车所在仓库、货位
        public string getCarsHousePosition(string carCode,ref string msg)
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                sb.Append("select b.barCode,c.* from bar_SheBeiBarCode_info b ");
                sb.Append("inner join fun_Cars_Info c on c.cCode = b.sbCode ");
                sb.Append("where barCode='"+ carCode + "'");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count < 1)
                {
                    msg = "找不到对应的工装车信息（"+ carCode+"）";
                    return msg;
                }
                if (string.IsNullOrWhiteSpace(table.Rows[0]["whCode"].ToString()))
                {
                    msg = "当前工装车（" + carCode + "）无仓库信息";
                    return msg;
                }
                if (string.IsNullOrWhiteSpace(table.Rows[0]["posCode"].ToString()))
                {
                    msg = "当前工装车（" + carCode + "）无货位信息";
                    return msg;
                }
                var position = table.Rows[0]["whCode"].ToString()+','+table.Rows[0]["posCode"].ToString();
                return position;
            }
            catch (Exception ex )
            {
                msg = ex.Message;
                return msg;
            }
        }

        /// <summary>
        /// 其他出库数据
        /// </summary>
        /// <param name="tempCode"></param>
        /// <returns></returns>
        private Dictionary<string, object> wareOutData(string tempCode, string baseCode, ref string errMsg)
        {
            Dictionary<string, object> returnDic = new Dictionary<string, object>();
            List<Dictionary<string, string>> dataList = new List<Dictionary<string, string>>();
            StringBuilder sb = new StringBuilder();
            sb.Append("select tempInfo.*,us.userName, ");
            sb.Append(" isnull(barInfo.number,'0') as barNumber,");
            sb.Append("barInfo.U8relationCode AS U8Code,");
            sb.Append("barInfo.color color,barInfo.trademark shangbiao,barInfo.cu_baozhuang baozhuang,  ");
            sb.Append("barInfo.cu_guohao guohao,  ");
            sb.Append("barInfo.cu_customer customName,barInfo.cuCode barCustomCode,invInfo.cu_xianggui xianggui,");
            sb.Append(" invInfo.proCode,invInfo.proName,invInfo.spec,invInfo.mUnit,");
            sb.Append(" invInfo.mUnitName,invInfo.cUnit,invInfo.cUnitName,isnull(invInfo.bFrees,'') bFrees  ");
            sb.Append(" from (select * from bar_TempScanData_info  ");
            sb.Append(" where 1=1 ");
            sb.Append(" and tempCode='" + tempCode + "')");
            sb.Append(" tempInfo ");
            //sb.Append(" LEFT  JOIN bar_ProductBarCode_info  barInfo ON tempInfo.barCode = barInfo.barCode");
            sb.Append(" LEFT  JOIN V_BarCode_Sub_Info  barInfo ON barInfo.barCode = tempInfo.barCode");
            //sb.Append(" LEFT  JOIN fun_CommonData_Info  cu ON cu.cCode = barInfo.cu_customer");
            //sb.Append(" and cu.isDel=0 and cu.status='Y' and cu.specFile='" + baseCode + "'");
            sb.Append(" LEFT  JOIN V_Products_info  invInfo ON invInfo.proCode = barInfo.proCode");
            sb.Append(" and invInfo.baseCode='" + baseCode + "' and invInfo.isDel=0 and invInfo.status='Y'");
            sb.Append(" LEFT  JOIN sys_users_info  us ON tempInfo.createuser = us.userCode");
            sb.Append(" and us.baseCode='" + baseCode + "' and us.isDel=0 and us.status='Y'");


            var table = cmd.GetDataTable(sb.ToString());

            List<string> reList = new List<string>();
            List<string> barList = new List<string>();
            Dictionary<string, string> dic;
            var irow = 0;

            foreach (DataRow r in table.Rows)
            {
                #region 判断存货绑定的自由项
                var bFrees = r["bFrees"].ToString();
                if (!string.IsNullOrWhiteSpace(bFrees))
                {

                    if (!bFrees.Contains("cfree1"))
                    {
                        r["color"] = "";//颜色
                    }
                    if (!bFrees.Contains("cfree2"))
                    {
                        r["guohao"] = "";//锅号
                    }
                    if (!bFrees.Contains("cfree3"))
                    {
                        r["shangbiao"] = "";//商标
                    }
                    if (!bFrees.Contains("cfree4"))
                    {
                        r["baozhuang"] = "";//包装/存放形式
                    }
                }
                else
                {
                    r["color"] = "";//颜色
                    r["guohao"] = "";//锅号
                    r["shangbiao"] = "";//商标
                    r["baozhuang"] = "";//包装/存放形式
                }
                #endregion

                //获取调用接口的条码
                if (!barList.Contains(r["barCode"].ToString()))
                {
                    barList.Add(r["barCode"].ToString());
                }
                var weight = "0";//重量
                var quantity = "0";//主计量(数量)
                var number = "0";//辅助计量（件数）
                if (r["mUnitName"].ToString().Equals("平米"))
                {
                    //weight = r["c_gongjin"].ToString();//入库重量
                }
                number = "1";//件数
                if (r["isBlue"].ToString().Equals("1"))
                {
                    quantity = r["barNumber"].ToString();//条
                }
                else
                {
                    quantity = "-" + r["barNumber"].ToString();//条
                }

                string s = string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}", r["proCode"].ToString(), r["color"].ToString(), r["shangbiao"].ToString(),
                    r["baozhuang"].ToString(), r["guohao"].ToString(),
                    r["xianggui"].ToString(), r["goodsPosition"].ToString(), r["targetGoodsPosition"].ToString());
                txt.AddLogMsg("条码汇总条件：" + s);
                txt.AddLogMsg("条码明细：" + r["barCode"] +",数量："+ r["barNumber"].ToString());
                if (!reList.Contains(s))
                {
                    irow++;
                    dic = new Dictionary<string, string>();
                    dic["irow"] = irow + "";//行号
                    dic["proCode"] = r["proCode"].ToString();
                    dic["proName"] = r["proName"].ToString();
                    dic["spec"] = r["spec"].ToString();
                    dic["number"] = number;//件数
                    dic["quantity"] = quantity;//条
                    dic["weight"] = weight;//入库重量
                    //dic["batch"] = r["batch"].ToString();//批号
                    var dlid = "";
                    var dispatch = new Dictionary<string, string>();
                    if (r["inOutType"].ToString().Equals("pos"))
                    {
                        getDisPatchList(r["outOrderCode"].ToString(), baseCode, ref dlid);
                        var para = new Dictionary<string, object>();
                        para["proCode"] = r["proCode"].ToString();
                        para["color"] = r["color"].ToString();//颜色
                        para["baozhuang"] = r["baozhuang"].ToString();//包装
                        para["shangbiao"] = r["shangbiao"].ToString();//商标
                        para["guohao"] = r["guohao"].ToString();//锅号
                        var dispatchList = getDisPatchsList(dlid, baseCode, para);
                        if (dispatchList == null || dispatchList.Count < 1)
                        {
                            errMsg = "未找到发货单数据";
                            new Tools.TxtLogHelper().AddLogMsg("未找到发货单数据:" + r["outOrderCode"].ToString() + JsonConvert.SerializeObject(para));
                            return null;
                        }
                        dispatch = getDisPatchsList(dlid, baseCode, para)[0];
                        dic["isodid"] = dispatch["iSOsID"];
                        dic["iorderdid"] = dispatch["iSOsID"];
                        dic["idlsid"] = dispatch["iDLsID"];
                        //dic["isodid"] = "";
                        //dic["iorderdid"] = "";
                        //dic["idlsid"] = "";
                    }
                    //dic["customer"] = r["barCustomCode"].ToString();//客户
                    //dic["customerName"] = r["customName"].ToString();//客户名称
                    dic["xianggui"] = r["xianggui"].ToString();//箱规
                    dic["color"] = r["color"].ToString();//颜色
                    dic["baozhuang"] = r["baozhuang"].ToString();//包装
                    dic["shangbiao"] = r["shangbiao"].ToString();//商标
                    dic["guohao"] = r["guohao"].ToString();//锅号
                    dic["goodsPosition"] = r["goodsPosition"].ToString();//调整前货位
                    dic["targetGoodsPosition"] = r["targetGoodsPosition"].ToString();//调整后货位
                    dic["mUnit"] = r["mUnit"].ToString();//主计量
                    dic["mUnitName"] = r["mUnitName"].ToString();//主计量名称
                    dic["cUnit"] = r["cUnit"].ToString();//辅助计量
                    dic["cUnitName"] = r["cUnitName"].ToString();//辅助计量名称
                    dic["batchMemo"] = "";//批次备注
                    dataList.Add(dic);
                    reList.Add(s);
                }
                else
                {
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        if (r["proCode"].ToString().Equals(dataList[i]["proCode"].ToString()) && r["color"].ToString().Equals(dataList[i]["color"].ToString()) &&
                           r["baozhuang"].ToString().Equals(dataList[i]["baozhuang"].ToString()) &&
                           r["shangbiao"].ToString().Equals(dataList[i]["shangbiao"].ToString()) &&
                            r["guohao"].ToString().Equals(dataList[i]["guohao"].ToString()) &&
                            r["xianggui"].ToString().Equals(dataList[i]["xianggui"].ToString())&&
                            r["goodsPosition"].ToString().Equals(dataList[i]["goodsPosition"].ToString())&&
                            r["targetGoodsPosition"].ToString().Equals(dataList[i]["targetGoodsPosition"].ToString()))
                        {
                            dataList[i]["number"] = (Convert.ToInt32(dataList[i]["number"].ToString()) + 1).ToString();
                            dataList[i]["quantity"] = (Convert.ToDecimal(dataList[i]["quantity"].ToString()) + Convert.ToDecimal(quantity)).ToString();
                            dataList[i]["weight"] = (Convert.ToDecimal(dataList[i]["weight"].ToString()) + Convert.ToDecimal(weight)).ToString();
                            break;
                        }
                    }
                }
            }
            returnDic.Add("barList", barList);
            returnDic.Add("dataList", dataList);
            return returnDic;
        }

        /// <summary>
        /// 其他出库数据
        /// </summary>
        /// <param name="tempCode"></param>
        /// <returns></returns>
        public Dictionary<string, object> carOutData(string tempCode, string baseCode, ref string errMsg)
        {
            Dictionary<string, object> returnDic = new Dictionary<string, object>();
            List<Dictionary<string, string>> dataList = new List<Dictionary<string, string>>();
            StringBuilder sb = new StringBuilder();
            sb.Append("select tempInfo.*,us.userName, ");
            sb.Append(" isnull(barInfo.number,'0') as barNumber,");
            //sb.Append("barInfo.U8relationCode AS U8Code,");
            //sb.Append("barInfo.color color,barInfo.trademark shangbiao,barInfo.cu_baozhuang baozhuang,  ");
            //sb.Append("barInfo.cu_guohao guohao,  ");
            //sb.Append("barInfo.cu_customer customName,barInfo.cuCode barCustomCode,invInfo.cu_xianggui xianggui,");
            sb.Append("'' AS U8Code,");
            sb.Append("case barInfo.proColor when '[]' then '' else barInfo.proColor  end color,case barInfo.brand when '[]' then '' else  barInfo.brand  end shangbiao,");
            sb.Append("'' baozhuang,'' guohao,'' customName,'' barCustomCode, ");
            sb.Append("invInfo.cu_xianggui xianggui,");
            sb.Append(" invInfo.proCode,invInfo.proName,invInfo.spec,invInfo.mUnit,");
            sb.Append(" invInfo.mUnitName,invInfo.cUnit,invInfo.cUnitName,isnull(invInfo.bFrees,'') bFrees  ");
            sb.Append(" from (select * from bar_TempScanData_info  ");
            sb.Append(" where 1=1 ");
            sb.Append(" and tempCode='" + tempCode + "')");
            sb.Append(" tempInfo ");
            //sb.Append(" LEFT  JOIN V_BarCode_Sub_Info  barInfo ON barInfo.barCode = tempInfo.barCode");
            sb.Append(" left join cart_product_info barInfo ON barInfo.deviceCode = tempInfo.barCode");
            sb.Append(" LEFT  JOIN V_Products_info  invInfo ON invInfo.proCode = barInfo.proCode");
            sb.Append(" and invInfo.baseCode='" + baseCode + "' and invInfo.isDel=0 and invInfo.status='Y'");
            sb.Append(" LEFT  JOIN sys_users_info  us ON tempInfo.createuser = us.userCode");
            sb.Append(" and us.baseCode='" + baseCode + "' and us.isDel=0 and us.status='Y'");

            var table = cmd.GetDataTable(sb.ToString());

            List<string> reList = new List<string>();
            List<string> barList = new List<string>();
            Dictionary<string, string> dic;
            var irow = 0;

            foreach (DataRow r in table.Rows)
            {
                #region 判断存货绑定的自由项
                var bFrees = r["bFrees"].ToString();
                if (!string.IsNullOrWhiteSpace(bFrees))
                {

                    if (!bFrees.Contains("cfree1"))
                    {
                        r["color"] = "";//颜色
                    }
                    if (!bFrees.Contains("cfree2"))
                    {
                        r["guohao"] = "";//锅号
                    }
                    if (!bFrees.Contains("cfree3"))
                    {
                        r["shangbiao"] = "";//商标
                    }
                    if (!bFrees.Contains("cfree4"))
                    {
                        r["baozhuang"] = "";//包装/存放形式
                    }
                }
                else
                {
                    r["color"] = "";//颜色
                    r["guohao"] = "";//锅号
                    r["shangbiao"] = "";//商标
                    r["baozhuang"] = "";//包装/存放形式
                }
                #endregion

                //获取调用接口的条码
                if (!barList.Contains(r["barCode"].ToString()))
                {
                    barList.Add(r["barCode"].ToString());
                }
                var weight = "0";//重量
                var quantity = "0";//主计量(数量)
                var number = "0";//辅助计量（件数）
                if (r["mUnitName"].ToString().Equals("平米"))
                {
                    //weight = r["c_gongjin"].ToString();//入库重量
                }
                number = "1";//件数
                if (r["isBlue"].ToString().Equals("1"))
                {
                    quantity = r["barNumber"].ToString();//条
                }
                else
                {
                    quantity = "-" + r["barNumber"].ToString();//条
                }

                string s = string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}", r["proCode"].ToString(), r["color"].ToString(), r["shangbiao"].ToString(),
                    r["baozhuang"].ToString(), r["guohao"].ToString(),
                    r["xianggui"].ToString(), r["goodsPosition"].ToString(), r["targetGoodsPosition"].ToString());
                txt.AddLogMsg("条码汇总条件：" + s);
                txt.AddLogMsg("条码明细：" + r["barCode"] + ",数量：" + r["barNumber"].ToString());
                if (!reList.Contains(s))
                {
                    irow++;
                    dic = new Dictionary<string, string>();
                    dic["irow"] = irow + "";//行号
                    dic["proCode"] = r["proCode"].ToString();
                    dic["proName"] = r["proName"].ToString();
                    dic["spec"] = r["spec"].ToString();
                    dic["number"] = number;//件数
                    dic["quantity"] = quantity;//条
                    dic["weight"] = weight;//入库重量
                    //dic["batch"] = r["batch"].ToString();//批号
                    var dlid = "";
                    var dispatch = new Dictionary<string, string>();
                    if (r["inOutType"].ToString().Equals("pos"))
                    {
                        getDisPatchList(r["outOrderCode"].ToString(), baseCode, ref dlid);
                        var para = new Dictionary<string, object>();
                        para["proCode"] = r["proCode"].ToString();
                        para["color"] = r["color"].ToString();//颜色
                        para["baozhuang"] = r["baozhuang"].ToString();//包装
                        para["shangbiao"] = r["shangbiao"].ToString();//商标
                        para["guohao"] = r["guohao"].ToString();//锅号
                        var dispatchList = getDisPatchsList(dlid, baseCode, para);
                        if (dispatchList == null || dispatchList.Count < 1)
                        {
                            errMsg = "未找到发货单数据";
                            new Tools.TxtLogHelper().AddLogMsg("未找到发货单数据:" + r["outOrderCode"].ToString() + JsonConvert.SerializeObject(para));
                            return null;
                        }
                        dispatch = getDisPatchsList(dlid, baseCode, para)[0];
                        dic["isodid"] = dispatch["iSOsID"];
                        dic["iorderdid"] = dispatch["iSOsID"];
                        dic["idlsid"] = dispatch["iDLsID"];
                        //dic["isodid"] = "";
                        //dic["iorderdid"] = "";
                        //dic["idlsid"] = "";
                    }
                    //dic["customer"] = r["barCustomCode"].ToString();//客户
                    //dic["customerName"] = r["customName"].ToString();//客户名称
                    dic["xianggui"] = r["xianggui"].ToString();//箱规
                    dic["color"] = r["color"].ToString();//颜色
                    dic["baozhuang"] = r["baozhuang"].ToString();//包装
                    dic["shangbiao"] = r["shangbiao"].ToString();//商标
                    dic["guohao"] = r["guohao"].ToString();//锅号
                    dic["goodsPosition"] = r["goodsPosition"].ToString();//调整前货位
                    dic["targetGoodsPosition"] = r["targetGoodsPosition"].ToString();//调整后货位
                    dic["mUnit"] = r["mUnit"].ToString();//主计量
                    dic["mUnitName"] = r["mUnitName"].ToString();//主计量名称
                    dic["cUnit"] = r["cUnit"].ToString();//辅助计量
                    dic["cUnitName"] = r["cUnitName"].ToString();//辅助计量名称
                    dic["batchMemo"] = "";//批次备注
                    dataList.Add(dic);
                    reList.Add(s);
                }
                else
                {
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        if (r["proCode"].ToString().Equals(dataList[i]["proCode"].ToString()) && r["color"].ToString().Equals(dataList[i]["color"].ToString()) &&
                           r["baozhuang"].ToString().Equals(dataList[i]["baozhuang"].ToString()) &&
                           r["shangbiao"].ToString().Equals(dataList[i]["shangbiao"].ToString()) &&
                            r["guohao"].ToString().Equals(dataList[i]["guohao"].ToString()) &&
                            r["xianggui"].ToString().Equals(dataList[i]["xianggui"].ToString()) &&
                            r["goodsPosition"].ToString().Equals(dataList[i]["goodsPosition"].ToString()) &&
                            r["targetGoodsPosition"].ToString().Equals(dataList[i]["targetGoodsPosition"].ToString()))
                        {
                            dataList[i]["number"] = (Convert.ToInt32(dataList[i]["number"].ToString()) + 1).ToString();
                            dataList[i]["quantity"] = (Convert.ToDecimal(dataList[i]["quantity"].ToString()) + Convert.ToDecimal(quantity)).ToString();
                            dataList[i]["weight"] = (Convert.ToDecimal(dataList[i]["weight"].ToString()) + Convert.ToDecimal(weight)).ToString();
                            break;
                        }
                    }
                }
            }
            returnDic.Add("barList", barList);
            returnDic.Add("dataList", dataList);
            return returnDic;
        }

        /// <summary>
        /// 产成品入库数据
        /// </summary>
        /// <param name="tempCode">临时码</param>
        /// <param name="msg">错误消息</param>
        /// <param name="barList">关联条码</param>
        /// <returns></returns>
        private List<Dictionary<string, string>> ProductInData(string tempCode, ref string msg, ref List<string> barList)
        {
            List<Dictionary<string, string>> dataList = new List<Dictionary<string, string>>();

            StringBuilder sb = new StringBuilder();
            sb.Append("select b.* from V_BarCode_Info b");
            sb.Append(" where b.barCode in(select barCode from bar_TempScanData_info ");
            sb.Append("where tempCode='" + tempCode + "')");
            var table = cmd.GetDataTable(sb.ToString());
            List<string> reList = new List<string>();

            Dictionary<string, string> dic;
            int rowCount = 0;
            foreach (DataRow r in table.Rows)
            {
                barList.Add(r["barCode"].ToString());
                dic = new Dictionary<string, string>();
                string proCode = r["proCode"].ToString();//存货编码
                string xinghao = r["c_xinghao"].ToString();//规格型号
                string mishu = r["c_mishu"].ToString();//单卷米数
                string customer = r["outCompanyName"].ToString();//客户
                string xilie = r["c_xilie"].ToString();//系列
                string plCode = r["planCode"].ToString();
                string newCode = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", proCode, xinghao, mishu, customer, xilie, plCode);
                if (!reList.Contains(newCode))
                {
                    rowCount++;
                    dic["irowno"] = Convert.ToString(rowCount);
                    dic["cinvcode"] = proCode;
                    dic["iquantity"] = r["number"].ToString();
                    dic["cfree1"] = xinghao;
                    dic["cfree2"] = customer;
                    dic["cfree3"] = mishu;
                    dic["cfree4"] = xilie;
                    dic["cbatch"] = r["c_plBatch"].ToString();
                    dic["inum"] = "1";
                    dataList.Add(dic);
                    reList.Add(r["proCode"].ToString());
                }
                else
                {
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        if (dataList[i]["cinvcode"] == r["proCode"].ToString() && dataList[i]["cfree1"] == r["c_xinghao"].ToString() && dataList[i]["cfree2"] == r["outCompanyName"].ToString() && dataList[i]["cfree3"] == r["c_mishu"].ToString() && dataList[i]["cfree4"] == r["c_xilie"].ToString() && dataList[i]["cbatch"] == r["c_plBatch"].ToString())
                        {
                            dataList[i]["iquantity"] = Convert.ToString(double.Parse(dataList[i]["iquantity"]) + double.Parse(r["number"].ToString()));
                            dataList[i]["inum"] = Convert.ToString(double.Parse(dataList[i]["inum"]) + 1);
                            break;
                        }
                    }
                }
            }

            return dataList;
        }
        /// <summary>
        /// 其他入库数据
        /// </summary>
        /// <param name="tempCode">临时码</param>
        /// <returns></returns>
        private List<Dictionary<string, string>> OtherInData(string tempCode)
        {
            List<Dictionary<string, string>> dataList = new List<Dictionary<string, string>>();

            StringBuilder sb = new StringBuilder();
            sb.Append("select isnull(proCode,'') proCode,barCode,");
            sb.Append(" isnull(number,'0') number from bar_ProductBarCode_info where ");
            sb.Append(" barCode in (select barCode from bar_TempScanData_info where  ");
            sb.Append("tempCode='" + tempCode + "')");
            var table = cmd.GetDataTable(sb.ToString());
            List<string> reList = new List<string>();
            sb.Clear();
            sb.Append("select proCode,retailPrice,wholePrice ");
            sb.Append(" from fun_productPrice_info where ");
            sb.Append("isdel=0");
            var pTable = cmd.GetDataTable(sb.ToString());//价格信息

            Dictionary<string, string> dic;
            foreach (DataRow r in table.Rows)
            {
                dic = new Dictionary<string, string>();
                if (!reList.Contains(r["proCode"].ToString()))
                {
                    dic["proCode"] = r["proCode"].ToString();
                    dic["weight"] = r["number"].ToString();
                    dic["number"] = "1";
                    #region 价格信息
                    var dr = pTable.Select("proCode='" + r["proCode"].ToString() + "'");
                    if (dr.Length < 1)
                    {
                        dic["price"] = "0";//如果没有价格信息就默认为0
                    }
                    else
                    {
                        dic["price"] = dr[0]["wholePrice"].ToString();
                    }

                    #endregion
                    dataList.Add(dic);
                    reList.Add(r["proCode"].ToString());
                }
                else
                {
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        if (dataList[i]["proCode"] == r["proCode"].ToString())
                        {
                            dataList[i]["weight"] = Convert.ToString(double.Parse(r["number"].ToString()) + double.Parse(dataList[i]["weight"]));
                            dataList[i]["number"] = Convert.ToString(int.Parse(dataList[i]["number"]) + 1);
                            break;
                        }
                    }
                }
            }

            return dataList;
        }
        /// <summary>
        /// 销售发票数据
        /// </summary>
        /// <param name="tempCode"></param>
        /// <returns></returns>
        private List<Dictionary<string, string>> InvoiceData(string tempCode, string customCode, ref string errMsg)
        {
            List<Dictionary<string, string>> dataList = new List<Dictionary<string, string>>();

            StringBuilder sb = new StringBuilder();
            sb.Append("select isnull(proCode,'') proCode,proName,barCode,");
            sb.Append(" isnull(number,'0') number from bar_ProductBarCode_info where ");
            sb.Append(" barCode in (select barCode from bar_TempScanData_info where  ");
            sb.Append("tempCode='" + tempCode + "')");
            var table = cmd.GetDataTable(sb.ToString());
            List<string> reList = new List<string>();
            sb.Clear();
            sb.Append("select proCode,retailPrice,wholePrice ");
            sb.Append(" from fun_productPrice_info where ");
            sb.Append("isdel=0");
            var pTable = cmd.GetDataTable(sb.ToString());//价格信息

            sb.Clear();
            sb.Append("select cuType from fun_Customs_info where cuCode='" + customCode + "'");
            var cuTable = cmd.GetDataTable(sb.ToString());
            if (cuTable.Rows.Count < 1)
            {
                errMsg = "无效客户数据";
                return null;
            }
            Dictionary<string, string> dic;
            foreach (DataRow r in table.Rows)
            {
                dic = new Dictionary<string, string>();
                if (!reList.Contains(r["proCode"].ToString()))
                {
                    dic["proCode"] = r["proCode"].ToString();
                    dic["proName"] = r["proName"].ToString();
                    dic["weight"] = r["number"].ToString();
                    dic["number"] = "1";
                    #region 价格信息
                    var dr = pTable.Select("proCode='" + r["proCode"].ToString() + "'");
                    if (dr.Length < 1)
                    {
                        errMsg = "存货无价格信息：" + r["proCode"].ToString();
                        return null;
                    }
                    else
                    {
                        if (cuTable.Rows[0]["cuType"].ToString() == "pifa")
                        {
                            dic["price"] = dr[0]["wholePrice"].ToString();
                        }
                        else
                        {
                            dic["price"] = dr[0]["retailPrice"].ToString();
                        }
                    }
                    #endregion
                    dataList.Add(dic);
                    reList.Add(r["proCode"].ToString());
                }
                else
                {
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        if (dataList[i]["proCode"] == r["proCode"].ToString())
                        {
                            dataList[i]["weight"] = Convert.ToString(double.Parse(r["number"].ToString()) + double.Parse(dataList[i]["weight"]));
                            dataList[i]["number"] = Convert.ToString(int.Parse(dataList[i]["number"]) + 1);
                            break;
                        }
                    }
                }
            }

            return dataList;
        }


        /// <summary>
        /// 其他出库数据
        /// </summary>
        /// <param name="tempCode"></param>
        /// <returns></returns>
        private List<Dictionary<string, string>> OtherOutData(string momBar, string usCode, string baseCode, ref string errMsg)
        {
            List<Dictionary<string, string>> dataList = new List<Dictionary<string, string>>();

            StringBuilder sb = new StringBuilder();
            sb.Append(" select *  ");
            sb.Append(" from bar_TempCutPlan_info cp");
            sb.Append(" left join bar_ProductBarCode_info bar on cp.childBar=bar.barCode");
            var table = cmd.GetDataTable(sb.ToString());
            List<string> reList = new List<string>();
            sb.Clear();
            sb.Append("select proCode,retailPrice,wholePrice ");
            sb.Append(" from fun_productPrice_info where ");
            sb.Append("isdel=0");
            var pTable = cmd.GetDataTable(sb.ToString());//价格信息

            Dictionary<string, string> dic;
            foreach (DataRow r in table.Rows)
            {
                dic = new Dictionary<string, string>();
                if (!reList.Contains(r["proCode"].ToString()))
                {
                    dic["proCode"] = r["proCode"].ToString();
                    dic["proName"] = r["proName"].ToString();
                    dic["weight"] = r["number"].ToString();
                    dic["number"] = "1";
                    #region 价格信息
                    var dr = pTable.Select("proCode='" + r["proCode"].ToString() + "'");
                    if (dr.Length < 1)
                    {
                        errMsg = "存货无价格信息：" + r["proCode"].ToString();
                        return null;
                    }
                    dic["price"] = dr[0]["wholePrice"].ToString();

                    #endregion
                    dataList.Add(dic);
                    reList.Add(r["proCode"].ToString());
                }
                else
                {
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        if (dataList[i]["proCode"] == r["proCode"].ToString())
                        {
                            dataList[i]["weight"] = Convert.ToString(double.Parse(r["number"].ToString()) + double.Parse(dataList[i]["weight"]));
                            dataList[i]["number"] = Convert.ToString(int.Parse(dataList[i]["number"]) + 1);
                            break;
                        }
                    }
                }
            }
            return dataList;
        }

        /// <summary>
        /// u8接口登录信息参数构建
        /// </summary>
        /// <param name="uTable"></param>
        /// <returns></returns>
        public Dictionary<string, object> createUserPar(string userCode, string baseCode, ref string errMsg)
        {
            StringBuilder sb = new StringBuilder();
            //var sAccID = Tools.ConfigReader.Reader["sAccID"];//账套号
            var sAccID = baseCode;
            var sys = new Dictionary<string, object>();
            sys["sAccID"] = sAccID;
            sys["sYear"] = DateTime.Now.Year;
            sys["sDate"] = getNowDate();
            sys["sServer"] = Tools.ConfigReader.Reader["BaseServerIP"];
            if (userCode == "admin")
            {
                sys["sUserID"] = "521";
                sys["sUserName"] = "独宇航";
                sys["sPassword"] = "123456";

            }
            else
            {
                sb.Append("select * from sys_users_info where userCode='" + userCode + "'");
                sb.Append(" and isSync='Y' and isDel='0' and status='Y' ");
                sb.Append(" and baseCode='" + sAccID + "'");
                var uTable = cmd.GetDataTable(sb.ToString());
                if (uTable.Rows.Count < 1)
                {
                    errMsg = "该账号无权限提交数据";
                    return null;
                }
                sys["sUserID"] = uTable.Rows[0]["userCode"].ToString();
                sys["sUserName"] = uTable.Rows[0]["userName"].ToString();
                if (string.IsNullOrWhiteSpace(uTable.Rows[0]["openPwd"].ToString()))
                {
                    errMsg = "系统密码与U8密码不匹配请先修改密码";
                    return null;
                }
                sys["sPassword"] = Tools.Encryption.DesDecrypt(uTable.Rows[0]["openPwd"].ToString());
            }

            return sys;
        }
        /// <summary>
        /// 获取参照该发货单生成的出库记录数量
        /// </summary>
        private ReturnResult getNumberMCode(string referOrderCode, string baseCode)
        {
            ReturnResult rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(" select * from bar_BarEntryRecords_main where 1=1");
                sb.Append(" and referOrderCode = '" + referOrderCode + "' and baseCode='" + baseCode + "'");
                var table = cuHelper.getData(sb.ToString(), baseCode);
                rsl.Data = table.Rows.Count;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        private List<Dictionary<string, string>> getDisPatchList(string cCode, string baseCode, ref string DLID)
        {

            StringBuilder sb = new StringBuilder();
            sb.Append("select * from DispatchList");
            sb.Append(" where 1=1 and cDLCode='" + cCode + "'");
            var dispatchList = cuHelper.getData(sb.ToString(), baseCode);
            if (dispatchList.Rows.Count > 0)
            {
                DLID = dispatchList.Rows[0]["DLID"].ToString();
            }
            return cmd.TableToDictionary(dispatchList);
        }
        private List<Dictionary<string, string>> getDisPatchsList(string dlid, string baseCode, Dictionary<string, object> dic)
        {
            var proCode = dic["proCode"].ToString();
            var color = dic["color"].ToString();
            var guohao = dic["guohao"].ToString();
            var shangbiao = dic["shangbiao"].ToString();
            var baozhuang = dic["baozhuang"].ToString();
            //var xilie = dic["customer"].ToString();
            //var xianggui = dic["xianggui"].ToString();
            StringBuilder sb = new StringBuilder();
            sb.Append("select iSOsID,iDLsID from DispatchLists");
            sb.Append(" where 1=1 and dlid='" + dlid + "' and cInvCode='" + proCode + "'");
            sb.Append(" and isnull(cFree1,'')='" + color + "' and isnull(cFree2,'')='" + guohao + "' and isnull(cFree3,'')='" + shangbiao + "' and isnull(cFree4,'')='" + baozhuang + "' ");
            //sb.Append(" and cDefine22='" + batch + "'");
            //sb.Append(" and cDefine23='" + xianggui + "'"); 
            var dispatchList = cuHelper.getData(sb.ToString(), baseCode);
            return cmd.TableToDictionary(dispatchList);
        }
        private List<Dictionary<string, string>> getSalebillVouch(string cSBVCode, string baseCode, ref string SBVID)
        {

            StringBuilder sb = new StringBuilder();
            sb.Append("select * from salebillvouch ");
            sb.Append(" where 1=1 and cSBVCode ='" + cSBVCode + "'");
            var dispatchList = cuHelper.getData(sb.ToString(), baseCode);
            if (dispatchList.Rows.Count > 0)
            {
                SBVID = dispatchList.Rows[0]["SBVID"].ToString();
            }
            return cmd.TableToDictionary(dispatchList);
        }
    }
}
